/***********************************************************************************************************************************
 *    Name: Shrink_TempDB.sql
 *  Author: Frank Figearo — http://www.sqlnerd.me/ — frank@sqlnerd.me
 * Summary: 
**/
USE TempDB;
CHECKPOINT;
DECLARE @tsql NVARCHAR(MAX)= N'USE TempDB;';
SELECT @tsql+= ' DBCC SHRINKFILE (N''' + name + N''', 1024);' FROM sys.database_files ORDER BY type, file_id;
PRINT @tsql;
EXECUTE (@tsql);